package com.define.ssh.action.admin;

import java.util.Date;

import javax.annotation.Resource;

import com.define.ssh.model.Func;
import com.define.ssh.service.FuncService;

/**
 * 功能管理
 * 
 * @author hcy
 * 
 */
public class FuncAction extends BaseAdminAction {
	private static final long serialVersionUID = 6L;

	/** 页面传递参数过来 */
	protected int pageSize;
	protected int pageNum;

	@Resource(name = "funcServiceImpl")
	private FuncService funcService;

	private Func func;

	/**
	 * 列表页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() {
		pager = funcService.findPager(pager);
		return LIST;
	}

	// 删除
	public String delete() {
		final StringBuffer logInfoStringBuffer = new StringBuffer("删除功能: ");
		for (final Long id : ids) {
			final Func ss = funcService.load(id);
			// 删除角色
			funcService.delete(ss);
		}
		logInfo = logInfoStringBuffer.toString();
		return ajax(Status.success, "删除成功!");
	}

	// 添加
	public String add() {
		return INPUT;
	}

	// 编辑
	public String edit() {
		func = funcService.load(id);
		return INPUT;
	}

	// 保存
	public String save() {
		func.setCreateDate(new Date());
		funcService.save(func);
		logInfo = "添加功能: " + func.getName();
		return ajax(Status.success, "添加功能成功");
	}

	// 更新
	public String update() {
		final Func func1 = funcService.load(id);
		func1.setName(func.getName());
		func1.setIsvalid(func.getIsvalid());
		func1.setRemark(func.getRemark());
		func1.setModifyDate(new Date());
		func1.setUrl(func.getUrl());
		funcService.update(func1);
		logInfo = "编辑功能: " + func.getName();
		return ajax(Status.success, "修改功能成功");
	}

	public Func getFunc() {
		return func;
	}

	public void setFunc(Func func) {
		this.func = func;
	}
}
